namespace NAct.Tests.Research
{
	using NUnit.Framework;
	using NUnit.Framework.ExtensionMethods;
	using Patterns;

	[ TestFixture ]
	public class PatternMatcherFixture
	{
		private const string SIMPLE_PATTERN = "given a person called (?<name>[a-z]+)";
		private const string SIMPLE_SOURCE = "given a person called Bob";

		private const string COMPLEX_PATTERN = "given a person called (?<forename>[a-z]+) (?<surname>[a-z]+) who is (?<age>[0-9]+) years old";
		private const string COMPLEX_SOURCE = "given a person called Joe Bloggs who is 25 years old";

		[ Test ]
		public void Should_be_able_to_extract_the_name()
		{
			IPatternMatcher matcher = new PatternMatcher( SIMPLE_PATTERN );
			IPatternParseResults results = matcher.Parse( SIMPLE_SOURCE );

			results.Count.Should( Be.EqualTo( 1 ), "Should only have one entry - 'Bob'" );
			results.Get( "name" ).Should( Be.EqualTo( "Bob" ) );
		}

		[ Test ]
		public void Should_provide_access_to_the_source()
		{
			IPatternMatcher matcher = new PatternMatcher( SIMPLE_PATTERN );
			IPatternParseResults results = matcher.Parse( SIMPLE_SOURCE );

			results.Source.Should( Be.EqualTo( SIMPLE_SOURCE ) );
		}

		[ Test ]
		public void Should_be_able_to_extract_the_forename_surname_and_age()
		{
			IPatternMatcher matcher = new PatternMatcher( COMPLEX_PATTERN );
			IPatternParseResults results = matcher.Parse( COMPLEX_SOURCE );

			results.Count.Should( Be.EqualTo( 3 ) );
			results.Get( "forename" ).Should( Be.EqualTo( "Joe" ) );
			results.Get( "surname" ).Should( Be.EqualTo( "Bloggs" ) );
			results.Get( "age" ).Should( Be.EqualTo( "25" ) );
		}
	}
}